// components/privacy/index.js
const util=require('../../utils/util')
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

/**
   * 组件的初始数据
   */
  data: {
    privacyContractName: '',
    showPrivacy: false,
    showPlayer:false
  },
  /**
   * 组件的生命周期
   */
  pageLifetimes: {
      show() {
          var that = this
          var getSystemInfoSync=wx.canIUse('getSystemInfoSync')
          var getPrivacySetting=wx.canIUse('getPrivacySetting')
          var version = wx.getSystemInfoSync().SDKVersion
          console.log('version',version)
          if(getSystemInfoSync && getPrivacySetting){
          if(util.compareVersion(version,'2.32.3') >= 0){
            
            wx.getPrivacySetting({
              success(res) {
                console.log(res)
                console.log(222222)
                  if (res.errMsg == "getPrivacySetting:ok") {
                      that.setData({
                          showPlayer:true,
                          privacyContractName: res.privacyContractName,
                          showPrivacy: res.needAuthorization
                      })
                      if(res.needAuthorization==false){
                        that.setData({
                          showPlayer:false
                        })
                      }
                  }

              },
              fail(err){
                console.log(err)
              }
          })
          }else{
            that.setData({
              showPrivacy: false,
              showPlayer:false
              })
          }
        }else{
          that.setData({
            showPrivacy: false,
            showPlayer:false
            })
        }
      }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    
    //打开隐私协议页面
    openPrivacyContract() {
      const _ = this
      wx.openPrivacyContract({
          fail: () => {
              wx.showToast({
                  title: '遇到错误',
                  icon: 'error'
              })
          }
      })
    },
    // 拒绝隐私协议
    hidePrivacy() {
      var that = this
      that.setData({
          showPrivacy: false,
    
      })
      // 直接退出小程序
        //  wx.exitMiniProgram()
    },
      // 同意隐私协议
      handleAgreePrivacyAuthorization() {
        var that = this
        that.setData({
            showPrivacy: false,
            showPlayer:false
        })
        this.triggerEvent('handleAgreePrivacyAuthorization')
    },
    showPrivacy:function(){
      var that = this
      that.setData({
          showPrivacy: true,
    
      })
    }
  }
})